package com.dstz.demo.rest.controller;

import com.dstz.base.api.aop.annotion.CatchErr;
import com.dstz.base.api.query.QueryFilter;
import com.dstz.base.api.response.impl.ResultMsg;
import com.dstz.base.rest.BaseController;
import com.dstz.demo.core.manager.PCompanyQualificationManager;
import com.dstz.demo.core.model.PCompanyQualification;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;


/**
 * 单位资质 控制器类<br/>
 * @author  aschs
 * </pre>
 */
@RestController
@RequestMapping("/sys/pCompanyQualification")
public class PCompanyQualificationController extends BaseController<PCompanyQualification>{
	@Resource
	PCompanyQualificationManager pCompanyQualificationManager;


	@Override
	protected String getModelDesc() {
		return "单位资质";
	}

	@PostMapping("/insert")
	@CatchErr("添加失败")
	public ResultMsg insertPCompanyQualification(@RequestBody PCompanyQualification pCompanyQualification){
		QueryFilter queryFilte=getQueryFilter(null);
		queryFilte.addParamsFilter("p_company_id",pCompanyQualification.getPCompanyId());
		List<PCompanyQualification> selectPCompanyQualification=pCompanyQualificationManager.selectPCompanyQualification(queryFilte);
		if (selectPCompanyQualification.size()<=0){
			pCompanyQualification.setPCompanyQualificationId(UUID.randomUUID().toString());
			pCompanyQualificationManager.insertPCompanyQualification(pCompanyQualification);
		}else {
			pCompanyQualification.setPCompanyQualificationId(selectPCompanyQualification.get(0).getPCompanyQualificationId());
			pCompanyQualificationManager.updatePDiachronicRecord(pCompanyQualification);
		}
		return getSuccessResult("添加成功");
	}

	@PostMapping("/update")
	@CatchErr("修改失败")
	public ResultMsg updatePCompanyQualification(@RequestBody PCompanyQualification pCompanyQualification){
		pCompanyQualificationManager.updatePDiachronicRecord(pCompanyQualification);
		return getSuccessResult("修改成功");
	}
}
